package com.audaque.springboot.foshanupload.web.esdatademo.model.pojo;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.*;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;

@Data
@Document(indexName = "blog", shards = 1, replicas = 1)
public class Blog {
    //使用 @Id 注解的字段作为文档的 _id 值
    @Id
    private Long blogId;

    @Field(type = FieldType.Text, analyzer = "ik_max_word", copyTo = "descriptiveContent")
    private String title;

    @Field(type = FieldType.Text)
    private String content;


    @MultiField(
            mainField = @Field(type = FieldType.Text, analyzer = "ik_max_word", searchAnalyzer = "ik_max_word"),
            otherFields = {
                    @InnerField(type = FieldType.Keyword, suffix = "keyword")
            }
    )
    private String author;

    //博客所属分类。
    @Field(type = FieldType.Keyword)
    private String category;

    //0: 未发布（草稿） 1：已发布 2：已删除
    @Field(type = FieldType.Integer)
    private int status;

    //序列号，用于给外部展示的id
    @Field(type = FieldType.Keyword)
    private String serialNum;


    @DateTimeFormat(pattern="yyyy-MM-ddHH:mm:ss")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @Field(type= FieldType.Date, format= DateFormat.custom, pattern="yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    @DateTimeFormat(pattern="yyyy-MM-ddHH:mm:ss")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @Field(type=FieldType.Date, format=DateFormat.custom, pattern="yyyy-MM-dd HH:mm:ss")
    private Date updateTime;



    /**
     * 封面图链接
     */
    @Field(type = FieldType.Keyword, index = false)
    String coverImage;


    /**
     * 描述
     */
    @Field(type = FieldType.Text, analyzer = "ik_max_word", copyTo = "descriptiveContent")
    String description;



    /**
     * 由其他属性copy而来，主要用于搜索功能，不需要储存数据
     */
    @JsonIgnore
    @Field(type = FieldType.Text, analyzer = "ik_max_word", ignoreFields = "descriptiveContent", store = false)
    String descriptiveContent;







}
